package com.dcxt.view;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.dcxt.config.Config;

public class MainActivity extends Activity {
	private TextView txtAddrView;
	private DisplayMetrics dm;
	private Button btnGo;
	private Config config;
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		dm = new DisplayMetrics();
		
		getWindowManager().getDefaultDisplay().getMetrics(dm);
		System.out.println(dm.heightPixels+" "+dm.widthPixels);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		getWindow().setLayout(dm.widthPixels, dm.heightPixels);
		requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
		setContentView(R.layout.main);
		txtAddrView = (TextView) findViewById(R.id.txt_addr);
		btnGo = (Button) findViewById(R.id.go);
		btnGo.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent webActivityIntent = new Intent();
				Bundle urlBundle = new Bundle();
				config.saveProperty("server.addr", txtAddrView.getText().toString());
				urlBundle.putString("url", txtAddrView.getText().toString());
				webActivityIntent.putExtras(urlBundle);
				webActivityIntent
						.setClass(MainActivity.this, WebActivity.class);
				startActivity(webActivityIntent);
			}
		});
		Config.setCtxt(this);
		config = Config.getInstance();
		String url = config.getProperty("server.addr");
		if (url != null && !"".equals(url)) {
			this.txtAddrView.setText(url);
		}else{
			this.txtAddrView.setText("http://172.21.11.205:8098/cook");
		}
	}

	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);

	}
}
